<?php

$appId = 'wx1fd42d01939a23d8';
$appsecret = 'f9fb10df8d82cdace1d1b5c8b45490fe';
$timestamp = time();
$jsapi_ticket = make_ticket($appId,$appsecret);
$nonceStr = make_nonceStr();
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$signature = make_signature($nonceStr,$timestamp,$jsapi_ticket,$url);

function make_nonceStr()
{
	$codeSet = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	for ($i = 0; $i<16; $i++) {
		$codes[$i] = $codeSet[mt_rand(0, strlen($codeSet)-1)];
	}
	$nonceStr = implode($codes);
	return $nonceStr;
}

function make_signature($nonceStr,$timestamp,$jsapi_ticket,$url)
{
	$tmpArr = array(
	'noncestr' => $nonceStr,
'timestamp' => $timestamp,
'jsapi_ticket' => $jsapi_ticket,
'url' => $url
);
ksort($tmpArr, SORT_STRING);
$string1 = http_build_query( $tmpArr );
$string1 = urldecode( $string1 );
$signature = sha1( $string1 );
return $signature;
}

function make_ticket($appId,$appsecret)
{
// access_token 应该全局存储与更新，以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("access_token.json"));
if ($data->expire_time < time()) {
$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appsecret;
$json = file_get_contents($TOKEN_URL);
$result = json_decode($json,true);
$access_token = $result['access_token'];

if ($access_token) {

$data->expire_time = time() + 7000;
$data->access_token = $access_token;
$fp = fopen("access_token.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}else{
$access_token = $data->access_token;
}

// jsapi_ticket 应该全局存储与更新，以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("jsapi_ticket.json"));
if ($data->expire_time < time()) {
$ticket_URL="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
$json = file_get_contents($ticket_URL);
$result = json_decode($json,true);
$ticket = $result['ticket'];
if ($ticket) {
$data->expire_time = time() + 7000;
$data->jsapi_ticket = $ticket;
$fp = fopen("jsapi_ticket.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}else{
$ticket = $data->jsapi_ticket;
}

return $ticket;
}

?>
<!DOCTYPE html>
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=yes">

	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta http-equiv="x-ua-compatible" content="IE=edge">
	<meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache">
	<meta http-equiv="Expires" content="0">

	<title>金地公园华玺</title>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> -->
	<!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
	<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
	<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> -->
	<!-- <link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css"> -->
	<!-- <link href="util/layerv2.0/need/layer.css"> -->
	<script src="util/layerv2.0/layer.js"></script>
	<link href="CSS/menu3.css" rel="stylesheet" type="text/css">
	<link href="./CSS/swiper-3.4.2.min.css" rel="stylesheet" type="text/css">
	<style>
		*{
			margin:0px;
			padding:0px;
		}
		html,body,iframe{
			width:100%;
			height:100%;
		}
	</style>
</head>

<body>
<!--承载页面，这里可以修改默认页面-->
<iframe class="iframe" src="./dist/index.html" style="border:none;"></iframe>

<script src="JS/jquery-3.3.1.min.js"></script>
<script src="./JS/config.js"></script>
<script src="./JS/swiper-3.4.2.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script>

	(function($){
		$.getUrlParam = function(name) {
			var reg  = new RegExp("(^|&)"+  name +"=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r!=null) return unescape(r[2]); return null;
		}})(jQuery);
	// 获取自动跳转的参数
	const autoPage = $.getUrlParam('autoPage');
	console.log("我來看看",autoPage);
	if(autoPage){
		// $(".iframe").attr("src",`./dist/index.html?autoPage=${autoPage}`)
		// http://www.zhangduo-technology.com/cjxt/dist/index.html?autoPage=1_1_1#/ppt?pageType=ppt_logo&configKey=brocadeCoordinate
		window.open(`http://www.zhangduo-technology.com/cjxt/dist/index.html?autoPage=${autoPage}`,"_self")
	}
	wx.config({
		debug: false,
		appId: '<?=$appId?>',
		timestamp: <?=$timestamp?>,
	nonceStr: '<?=$nonceStr?>',
			signature: '<?=$signature?>',
			jsApiList: [
		'checkJsApi',
		'onMenuShareTimeline',
		'onMenuShareAppMessage',
		'onMenuShareQQ',
		'onMenuShareWeibo',
		'openLocation',
		'getLocation'
	]
	});

	wx.ready(function () {
		<?php
		if(!empty($_SESSION['uid'])){
			// $title = $_SESSION['user_info'][chengjianxioatun'realname'].'-'.$_SESSION['user_info']['mobile'].'-邢台富力城';
			$title = '金地公园华玺';
			$link = "http://www.zhangduo-technology.com/JinDiGongYuanHuXiIpadH5/index.php?share=".$_SESSION['uid'];
		}else{
			$title = '金地公园华玺';
			$link = "http://www.zhangduo-technology.com/JinDiGongYuanHuXiIpadH5/index.php";
		}
				?>
		var link = "<?=$link?>";
		var shareData = {
			title: "<?=$title?>",
			desc: '金地·公园华是金地落地廊坊打造的风华系2.0进阶新作，TOP2金地物业加持，项目择址城市新中心龙河中央商务区，200亩富氧中央公园为邻，21万方商业综合体一路之隔，享一站式全龄优教，步行5分钟高效生活圈',
			link: link,
			imgUrl: 'http://sanwei.sanweiyitivr.com/jdgyhx/logo.jpg',
			success: function(){
				$.post('share.php?do=share',{url:link},function(res){},'json');
			}
		};
		wx.onMenuShareAppMessage(shareData);
		wx.onMenuShareTimeline(shareData);
	});

	wx.error(function (res) {
		alert(res.errMsg);
	});
</script>
</body>
</html>


 
